/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package aeronef;

import aeronef.model.Ship;
import com.jme3.asset.AssetManager;
import com.jme3.font.BitmapFont;
import com.jme3.font.BitmapText;
import com.jme3.scene.Node;
import com.jme3.ui.Picture;

/**
 *
 * @author Hagan
 */
public class IngameHud {
    
    protected int width;
    protected int height;
    
    protected AssetManager assetManager;
    protected BitmapFont guiFont;
    protected Node guiNode;
    
    protected BitmapText message;
    protected BitmapText orderTurn;
    protected BitmapText orderSpeed;
    protected BitmapText orderClimb;
    
    public IngameHud(AssetManager assetManager, Node guiNode, int width, int height) {
        this.assetManager = assetManager;
        this.guiNode = guiNode;
        this.height = height;
        this.width = width;
        this.guiFont = assetManager.loadFont("Fonts/roughType32b.fnt");
    }
    
    public void init() {        
        
        Picture pic = new Picture("HUD Picture");
        pic.setImage(assetManager, "Textures/gui/page.png", true);
        pic.setWidth(1280);
        pic.setHeight(400);
        pic.setPosition(0, -250);
        System.out.println ("height = " + height + " width = " + width);
        guiNode.attachChild(pic);
        
        message = initText(message, 200, 0);
        orderTurn = initText(orderTurn, 400, 0);
        orderSpeed = initText(orderSpeed, 600, 0);
        orderClimb = initText(orderClimb, 800, 0);
        

    }
    
    
    
    public void clearGui() {
        guiNode.detachAllChildren();
    }
    
    public void updateShipDetails(Ship ship) {
        
        orderTurn.setText("turn " + ship.getOrderTurn().toString());
        orderSpeed.setText("speed " + ship.getOrderSpeed().toString());
        orderClimb.setText("climb " + ship.getOrderClimb().toString());
    }
    
    public void showMessage(String msg) {
        message.setText(msg);
    }
    
    private BitmapText initText(BitmapText text, float x, float y) {
            
        text = new BitmapText(guiFont, false);
        text.setSize(guiFont.getCharSet().getRenderedSize());
        text.setText("-");
        text.setLocalTranslation(x, (y+text.getLineHeight()), 0);
        guiNode.attachChild(text);
        return text;
    }
}
